﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars;
using PMSGSC.Common;
using System.IO;
using DevExpress.XtraBars.Helpers;
using PMSGSC.App.Report;
using PMSGSC.App.Sys;
using DevExpress.XtraEditors;
using PMSGSC.DAL;
using System.Threading;

namespace PMSGSC.App
{
    public partial class frmMain : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        public frmMain()
        {
            InitializeComponent();
            LoadSkin();
            flag = true;
            txtUserName.Caption = UserLogin.Name;
            
        }

        private static void LoadSkin()
        {
            DevExpress.Skins.SkinManager.EnableFormSkins();
            DevExpress.UserSkins.BonusSkins.Register();
            DevExpress.UserSkins.OfficeSkins.Register();
            DevExpress.LookAndFeel.DefaultLookAndFeel obj = new DevExpress.LookAndFeel.DefaultLookAndFeel();
            try
            {
                LookAndFeelSettings.Load("LookAndFeelSettings.dat");
            }
            catch
            {
                obj.LookAndFeel.SetSkinStyle("Blue");
            }
        }

        private void btnServiceCode_ItemClick(object sender, ItemClickEventArgs e)
        {
            LoadServiceCode();
        }

        private void LoadServiceCode()
        {
            frmServiceCode serviceCode = new frmServiceCode();
            serviceCode.MdiParent = this;
            serviceCode.Show();
        }
        public static Ship ship;
        public static Employee UserLogin;
        private void frmMainFinal_Load(object sender, EventArgs e)
        {
        }

        private void btnMaker_ItemClick(object sender, ItemClickEventArgs e)
        {
            LoadMaker();
        }

        private void LoadMaker()
        {
            frmMaker maker = new frmMaker();
            maker.MdiParent = this;
            maker.Show();
        }

        private void btnVendor_ItemClick(object sender, ItemClickEventArgs e)
        {
            LoadVendor();
        }

        private void LoadVendor()
        {

            frmVendor vendor = new frmVendor();
            vendor.MdiParent = this;
            vendor.Show();
        }

        private void btnCertificateType_ItemClick(object sender, ItemClickEventArgs e)
        {
            LoadCertificateType();
        }

        private void LoadCertificateType()
        {
            frmCertificateType certificateType = new frmCertificateType();
            certificateType.MdiParent = this;
            certificateType.Show();
        }

        private void btnStock_ItemClick(object sender, ItemClickEventArgs e)
        {
            LoadStock();
        }

        private void LoadStock()
        {
            frmStock stock = new frmStock();
            stock.MdiParent = this;
            stock.Show();
        }

        private void btnStockUnit_ItemClick(object sender, ItemClickEventArgs e)
        {
            LoadStockUnit();
        }

        private void LoadStockUnit()
        {
            frmUnits unit = new frmUnits();
            unit.MdiParent = this;
            unit.Show();
        }

        private void btnDepartment_ItemClick(object sender, ItemClickEventArgs e)
        {
            LoadDepartment();
        }

        private void LoadDepartment()
        {
            frmDepartment department = new frmDepartment();
            department.MdiParent = this;
            department.Show();
        }

        private void btnEmployee_ItemClick(object sender, ItemClickEventArgs e)
        {
            LoadEmployee();
        }

        private void LoadEmployee()
        {
            frmEmployee employee = new frmEmployee();
            employee.MdiParent = this;
            employee.Show();
        }

        private void btnLocation_ItemClick(object sender, ItemClickEventArgs e)
        {
            LoadLocation();
        }

        private void LoadLocation()
        {
            frmLocation location = new frmLocation();
            location.MdiParent = this;
            location.Show();
        }

        private void btnStatusComp_ItemClick(object sender, ItemClickEventArgs e)
        {
            LoadStatusComp();
        }

        private void LoadStatusComp()
        {
            frmStatusOfComponent statusOfComponent = new frmStatusOfComponent();
            statusOfComponent.MdiParent = this;
            statusOfComponent.Show();
        }

        private void btnStatusJob_ItemClick(object sender, ItemClickEventArgs e)
        {
            LoadStatusJob();
        }

        private void LoadStatusJob()
        {
            frmStatusOfJob statusJob = new frmStatusOfJob();
            statusJob.MdiParent = this;
            statusJob.Show();
        }

        private void btnShip_ItemClick(object sender, ItemClickEventArgs e)
        {
            LoadShip();
        }

        private void LoadShip()
        {
            frmShip ship = new frmShip();
            ship.MdiParent = this;
            ship.Show();
        }

        private void btnJobDescript_ItemClick(object sender, ItemClickEventArgs e)
        {
            LoadDescript();
        }

        private void LoadDescript()
        {
            frmJobDescription jobDescription = new frmJobDescription(this);
            jobDescription.MdiParent = this;
            jobDescription.Show();
        }

        public static bool flag;
        private void btnSelectShip_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (this.MdiChildren.Length == 0)
                SelectShip();
        }

        private static void SelectShip()
        {
            frmSelectShip selectShip = new frmSelectShip();
            selectShip.Show();
        }

        private void btnComponent_ItemClick(object sender, ItemClickEventArgs e)
        {
            Component();
        }

        private void Component()
        {
            frmFilterComponent searchComponent = new frmFilterComponent(this);
            searchComponent.ShowDialog();
        }

        private void btnComponentHierachy_ItemClick(object sender, ItemClickEventArgs e)
        {
            ComponentHierachy();
        }

        private void ComponentHierachy()
        {
            frmComponentHierachy componentHierachy = new frmComponentHierachy(this);
            componentHierachy.MdiParent = this;
            componentHierachy.Show();
        }

        private void btnWorkOrder_ItemClick(object sender, ItemClickEventArgs e)
        {
            WorkOrder();
        }

        private void WorkOrder()
        {
            frmWorkOrder workOrder = new frmWorkOrder(this);
            workOrder.ShowDialog();
        }

        private void btnRequireWork_ItemClick(object sender, ItemClickEventArgs e)
        {
            RequireWork();
        }

        private void RequireWork()
        {
            frmRequistionWork requireWork = new frmRequistionWork(this);
            requireWork.ShowDialog();
        }

        private void btnUpdateCounter_ItemClick(object sender, ItemClickEventArgs e)
        {
            UpdateCounter();
        }

        private void UpdateCounter()
        {
            frmFilterCounter updateCounter = new frmFilterCounter(this);
            updateCounter.ShowDialog();
        }

        private void btnCounterHistory_ItemClick(object sender, ItemClickEventArgs e)
        {
            History();
        }

        private void History()
        {
            frmCounterHistory counterHistory = new frmCounterHistory();
            counterHistory.MdiParent = this;
            counterHistory.Show();
        }

        private void btnStatusEquipment_ItemClick(object sender, ItemClickEventArgs e)
        {
            StatusEquipment();
        }

        private void StatusEquipment()
        {
            frmReviewStatusOfEquipment statusEquipment = new frmReviewStatusOfEquipment(this);
            statusEquipment.ShowDialog();
        }

        private void btnReportWork_ItemClick(object sender, ItemClickEventArgs e)
        {
            
        }
        private static void DeleteFiles()
        {
            try
            {
                string Address = Application.StartupPath + "\\Attachment\\";
                string[] files = Directory.GetFiles(Address);
                for (int i = 0; i < files.Length; i++)
                {
                    FileInfo fileInfo = new FileInfo(files[i]);
                    fileInfo.Delete();
                }
            }
            catch { }
        }

        private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            LookAndFeelSettings.Save("LookAndFeelSettings.dat");
            DeleteFiles();
        }

        private void btnOverDueWork_ItemClick(object sender, ItemClickEventArgs e)
        {
            OverDueJob();
        }

        private void OverDueJob()
        {
            frmFilterOverdueWork overDueWork = new frmFilterOverdueWork(this);
            overDueWork.ShowDialog();
        }

        private void btnStockItem_ItemClick(object sender, ItemClickEventArgs e)
        {
            StockItem();
        }

        private void StockItem()
        {
            frmFilterStockItem filterStockItem = new frmFilterStockItem(this);
            filterStockItem.Show();
        }

        private void btnStockIn_ItemClick(object sender, ItemClickEventArgs e)
        {
            StockIn();
        }

        private void StockIn()
        {
            frmStockIn stockIn = new frmStockIn(null, this);
            stockIn.MdiParent = this;
            stockIn.Show();
        }

        private void btnStockOut_ItemClick(object sender, ItemClickEventArgs e)
        {
            StockOut();
        }

        private void StockOut()
        {
            frmStockOut stockIn = new frmStockOut(null, this);
            stockIn.MdiParent = this;
            stockIn.Show();
        }

        private void btnIOList_ItemClick(object sender, ItemClickEventArgs e)
        {
            IOLIst();
        }

        private void IOLIst()
        {
            frmFilterIOList ioStock = new frmFilterIOList(this);
            ioStock.ShowDialog();
        }

        private void btnRound_ItemClick(object sender, ItemClickEventArgs e)
        {
            Round();
        }

        private void Round()
        {
            frmRound round = new frmRound(this);
            round.MdiParent = this;
            round.Show();
        }
        private void barSubItem1_ItemClick(object sender, ItemClickEventArgs e)
        {
            SkinHelper.InitSkinPopupMenu(barSubItem1);
        }

        private void DashBoardItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            DashBoard();
        }

        private void DashBoard()
        {
            frmDashBoard dashBoard = new frmDashBoard(this);
            dashBoard.MdiParent = this;
            dashBoard.Show();
        }

        private void SwitchDepartmentItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            SelectShip();
        }

        private void UserItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
           
        }

        private void ConfigureItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {

        }

        private void InforShipItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {

        }

        private void ChangePassItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {

        }

        private void SignOutItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {

        }

        private void MakerItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            LoadMaker();
        }

        private void VendorItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            LoadVendor();
        }

        private void Stock_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            LoadStock();
        }

        private void StockUnitItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            LoadStockUnit();
        }

        private void DepartmentItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            LoadDepartment();
        }

        private void EmployeeItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            LoadEmployee();
        }

        private void LocationItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            LoadLocation();
        }

        private void StatusItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            LoadStatusComp();
        }

        private void StatusJobItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            LoadStatusJob();
        }

        private void ServiceCodeItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            LoadServiceCode();
        }

        private void JobDescriptItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            LoadDescript();
        }

        private void CertificateTypeItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            LoadCertificateType();
        }

        private void ComponentItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Component();
        }

        private void CompHiea_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            ComponentHierachy();
        }

        private void WorkOrderItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            WorkOrder();
        }

        private void RequireWorkItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            RequireWork();
        }

        private void RoundITem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Round();
        }

        private void CounterItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            UpdateCounter();
        }

        private void HistoryItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            History();
        }

        private void StatusEquipItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            StatusEquipment();
        }

        private void ReportWorkItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            
        }

        private void OverDueItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            OverDueJob();
        }

        private void WorkCompleteItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {

        }

        private void ComsumableItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {

        }

        private void StockItemITem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            StockItem();
        }

        private void IEITem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {

        }

        private void InStockITem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
           
        }

        private void IOListItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            IOLIst();
        }

        private void StockInItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            StockIn();
        }

        private void StockOutItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            StockOut();
        }

        private void ManualItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            
        }

        private void barButtonItem12_ItemClick(object sender, ItemClickEventArgs e)
        {
        }

        private void btnCertificate_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmCertificate cerfiticate = new frmCertificate(null);
            cerfiticate.MdiParent = this;
            cerfiticate.Show();
        }

        private void btnCloseJob_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmCloseJob closeJob = new frmCloseJob(this);
            closeJob.ShowDialog();
        }

        private void btnDashBoard_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmDashBoard dashBoard = new frmDashBoard(this);
            dashBoard.MdiParent = this;
            dashBoard.Show();
        }

        private void barButtonItem13_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmFilterHistory history = new frmFilterHistory(this);
            history.Show();
        }

        private void btnConsumable_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmConsumableStock reportStockIn = new frmConsumableStock(this);
            reportStockIn.ShowDialog();
        }

        private void btnWorkComplete_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmFilterWorkComplete workComplete = new frmFilterWorkComplete(this);
            workComplete.ShowDialog();
        }

        private void btnInfor_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmInFor infor = new frmInFor();
            infor.ShowDialog();
        }

        private void btnConfigure_ItemClick(object sender, ItemClickEventArgs e)
        {
            XtraMessageBox.Show("This function's building !", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void btnUser_ItemClick(object sender, ItemClickEventArgs e)
        {
            XtraMessageBox.Show("This function's building !", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void btnBackup_ItemClick(object sender, ItemClickEventArgs e)
        {
            XtraMessageBox.Show("This function's building !", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void btnRestore_ItemClick(object sender, ItemClickEventArgs e)
        {
            XtraMessageBox.Show("This function's building !", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void btnChangePass_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmChangePassword changePass = new frmChangePassword();
            changePass.ShowDialog();
        }

        private void btnSignOut_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmMain.ship = null;
            frmMain.UserLogin = null;
            flag = false;
            Thread thread = new Thread(new ThreadStart(ThreadProc));
            thread.Start();
            this.Close();

        }
        public static void ThreadProc()
        {
            Application.Run(new frmLogin());
        }

        private void btnExit_ItemClick(object sender, ItemClickEventArgs e)
        {
            Application.Exit();
        }
    }
}